import api from '../index'
import type { ResponseData } from '../index'
import type { ClassifyItem } from '.'
import type {TabbarPageItem} from '@/common/stores/init'

export interface StoreInfo {
	collectedCount : number//收藏数
	customShareImg : string //自定义分享图
	description : string//店铺简介
	hasCustomShare : number //是否自定义分享
	hasCollected : number //是否已收藏
	hasOwn : 0 | 1, //是否为自营店铺
	storeHasOwn : 0 | 1, //是否为自营店铺
	id : string
	logo : string //logo
	name : string //名称
	type:number //店铺类型
	productCount : number //商品数
	averageScore : number //评分
	
}

// 店铺详情
export const getStoreDetail = (data : { id : string }) =>
	api.get<ResponseData<StoreInfo>>('merchant/customer/store/detail', {
		data,
		custom: {
			auth: false
		}
	})
// 店主信息
export const getStoreOwnerDetail = (data : { storeId : string }) =>
	api.get<ResponseData<{
		storeLogo : string
		storeName : string
		storeSalt : string
		storeId : string
	}>>('merchant/customer/store/storeOwner', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	})
// 店铺装修详情
export const getStoreHomeLayout = (id : string) =>
	api.get<ResponseData<TabbarPageItem>>(`merchant/customer/page/index/${id}`, {
		custom: {
			auth: false
		}
	})
// 店铺其余页面装修详情
export const getStoreLayoutPage = (id : string) =>
	api.get(`merchant/customer/page/detail/${id}`, {
		custom: {
			auth: false
		}
	})

// 店铺分组
export const getStoreGrouping = (data : {
	storeId : string,
	pid ?: number | string
}) =>
	api.get<ResponseData<ClassifyItem[]>>('merchant/customer/store/product/grouping', {
		data,
		custom: {
			auth: false
		}
	}
	)
// 获取用户申请入驻店铺的状态
export const getUserRegisterStoreState = () =>
	api.get<ResponseData<{
		state:0|1|2|3
		rejectRemark?:string
	}>>('merchant/customer/store/register/check', {
		custom: {
			isLoading: true
		}
	})
export interface LicensesItem {
	name:string
	id:number
}
// 获取营业执照类型列表
export const getLicensesList = () =>
	api.get<ResponseData<LicensesItem[]>>('merchant/store/license/type/list')
// // 申请商家入驻发送验证码
// export const merchantRegisterSms = (countryId : string, phone : string) =>
// 	api.post(`merchant/register/sms/${countryId}/${phone}`,)
// 申请商家入驻
export interface StoreExamineParams {
	type:string
	name: string
	licenseType: string
	licenseImgs: string[],
	logo: string[],
	creditCode: string
	licenseAddrProvince: string|number
	licenseAddrCity: string|number
	licenseAddrArea: string|number
	licenseAddrTown: string|number
	licenseAddrDetail: string
	legalPrincipalName: string
	legalPrincipalIdcard: string
	legalPrincipalIdcardImgs: string[],
	shopkeeperName: string
	shopkeeperTelephone: string
	parentPhone: string
	realScenePhoto: [],
	beginTime: string
	endingTime:string
	locationLongitude: string|number
	locationLatitude:string|number
	countryId?:number
	industry?:string
}
export const postStoreExamine = (data : StoreExamineParams) =>
	api.post('merchant/customer/store/register/submit', {
		data,
		custom: {
			isLoading: true
		}
	})
// 获取商家协议
export const getMerchantAgreement = () =>
	api.get('system/api/basics/store', {
		custom: {
			auth: false
		}
	})